<?php
	mysql_pconnect('localhost', 'root', '');
	mysql_select_db('studial');


	function isTAorTeacher($id)
	{
		$result = mysql_query("select * from `works` where `user_id` = '".$id."';");
		print_r($result);
		$rows = mysql_fetch_array($result);
		if($rows['role'] == 4 || $rows['role'] == 5)
			return 1;
		return 0;
			// 1 -> sinh vien
			// 2 -> nghien cuu sinh
			// 3 -> tro giang
			// 4 -> giang vien	
	}

	function iscourseteacher($id)
	{
		$result = mysql_query("select * from `courses` where `administrator_id` = '".$id."';");
		print_r($result);
		$rows_num = mysql_num_rows($result);
		return $rows_num;
	}
	
	if(isset($_COOKIE['studialuserid']))
	{
		$id = $_GET['id'];
		$user_id = $_COOKIE['studialuserid'];
		isTAorTeacher($user_id);
		iscourseteacher($user_id);
		if(isTAorTeacher($user_id) == 1 || iscourseteacher($user_id) == 1)
		{
			mysql_query("delete from `assignment_submission` where `assignment_id` = '".$id."';");
			mysql_query("delete from `assignments` where `id` = '".$id."';");	
			header ('location: eventlist.php?id='.$_COOKIE['studialcourseid']);
		}
	}
	else
	{
		header ('location: ../unlogged/index.php');
	}
	



	

?>